#include "../src/EventFileDriver.h"
#include "../src/EventList.h"
#include "../src/GroupTable.h"

#include <stdio.h>

int
main(void)
{
	GroupTable *g_table;
	int	    status;

	g_table = group_table_new();
	event_file_driver_set_file(EVENT_FILE_DRIVER(g_table),
				   "grouptable.efd");

	status = event_file_driver_loader(EVENT_FILE_DRIVER(g_table));
	if (status != EVENT_FILE_DRIVER_SUCCESS) {
		printf("打开文件失败！(code: %d)\n尝试创建文件 ......\n",
		       status);
		status = event_file_driver_create(EVENT_FILE_DRIVER(g_table));
		if (status != EVENT_FILE_DRIVER_SUCCESS) {
			printf("创建文件错误！(code: %d)\n", status);
			return status;
		} else {
			printf("创建文件成功！\n");
		}
	} else {
		printf("打开文件成功！\n");
		__group_table_print(g_table, (euint32)(1010003));
	}
	/*
        EventString *str;
        char         buf[10];
        GroupItem  *g_item;
        for (int i = 0; i < 1000; ++i) {
                g_item              = group_item_new();
                g_item->group_id    = (euint32)(1010000 + i);
                g_item->user_id     = (euint32)(1210000 + i);
                g_item->create_date = time(NULL);
                g_item->modify_date = time(NULL);
                sprintf(buf, "group%d", i);
                str = event_string_new(buf);
                group_item_set_group_name(g_item, str);
                event_object_unref(str);
                g_item->can_join    = true;
                g_item->g_can_write = false;
                for (int j = 0; j < 550; ++j) {
                        group_item_set_member(g_item,
                                              (euint32)(1210000 + j),
                                              (j % 2 ? true : false));
                }
                __group_table_add(g_table, g_item);
        }
        getchar();
        status = event_file_driver_dump(EVENT_FILE_DRIVER(g_table));
        if (status != EVENT_FILE_DRIVER_SUCCESS)
                printf("写入文件失败！(code: %d)\n", status);
        else
                printf("写入文件成功。\n");
*/
	event_object_unref(g_table);

	return 0;
}